package com.sky.service.impl;

import com.sky.entity.Category;
import com.sky.entity.Dish;
import com.sky.mapper.CategoryMapper;
import com.sky.mapper.DishMapper;
import com.sky.service.UserDishService;
import com.sky.vo.CategoryVO;
import com.sky.vo.DishVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserDishServiceImpl implements UserDishService {
    @Autowired
    private DishMapper dishMapper;

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public List<DishVO> list(String categoryId) {

        List<DishVO> resultDishVO = dishMapper.getForUserByCategoryId(categoryId);

        for (DishVO dishVO : resultDishVO) {
            dishVO.setFlavors(dishMapper.getFlavorsById(Math.toIntExact(dishVO.getId())));
        }

        return resultDishVO;
    }

    /*
     * 获取分类列表
     * */
    @Override
    public List<Category> getCategoryList() {
        List<Category> list = categoryMapper.getCategory();
        return list;
    }


}
